package com.example.demo.controller;

import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.example.demo.entity.User;
import com.example.demo.qo.UserQo;
import com.example.demo.service.IUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;

/**
 * Created by Administrator on 2017/7/24.
 */
@Controller
@RequestMapping("/user")
public class UserController {

    @Autowired
    private IUserService userService;

    @RequestMapping("/login")
    public ModelAndView login(){
        return new ModelAndView("app/login");
    }

    @RequestMapping("/index")
    public ModelAndView index(){
        return new ModelAndView("app/index");
    }

    @RequestMapping("/registration")
    public ModelAndView registration(){
        return new ModelAndView("app/registration");
    }

    @RequestMapping("/doRegistration")
    public ModelAndView doRegistration(User user){
        //select * from d26_user where login_name = {}  limit 1
        User userDB = userService.selectOne(new EntityWrapper<User>().eq("login_name",user.getLoginName()));
        if(userDB != null){
            return new ModelAndView("app/registration").addObject("error_info","您的登陆名重复！");
        }
        userService.insert(user);
        return new ModelAndView("app/login");
    }


    @RequestMapping("/userList")
    public ModelAndView userList(){
        return new ModelAndView("app/user_list");
    }
}
